<?xml version="1.0" encoding="ascii"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
          "DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>pygrib.index</title>
  <link rel="stylesheet" href="epydoc.css" type="text/css" />
  <script type="text/javascript" src="epydoc.js"></script>
</head>

<body bgcolor="white" text="black" link="blue" vlink="#204080"
      alink="#204080">
<!-- ==================== NAVIGATION BAR ==================== -->
<table class="navbar" border="0" width="100%" cellpadding="0"
       bgcolor="#a0c0ff" cellspacing="0">
  <tr valign="middle">
  <!-- Home link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="pygrib-module.html">Home</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Tree link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="module-tree.html">Trees</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Index link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="identifier-index.html">Indices</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Help link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="help.html">Help</a>&nbsp;&nbsp;&nbsp;</th>

      <th class="navbar" width="100%"></th>
  </tr>
</table>
<table width="100%" cellpadding="0" cellspacing="0">
  <tr valign="top">
    <td width="100%">
      <span class="breadcrumbs">
        <a href="pygrib-module.html">Module&nbsp;pygrib</a> ::
        Class&nbsp;index
      </span>
    </td>
    <td>
      <table cellpadding="0" cellspacing="0">
        <!-- hide/show private -->
      </table>
    </td>
  </tr>
</table>
<!-- ==================== CLASS DESCRIPTION ==================== -->
<h1 class="epydoc">Class index</h1><p class="nomargin-top"></p>
<pre class="base-tree">
object --+
         |
        <strong class="uidshort">index</strong>
</pre>

<hr />
<p>index(filename, *args)</p>
  <p>returns grib index object given GRIB filename indexed by keys given in
  *args.  The <a href="pygrib.index-class.html#select" 
  class="link">select</a> or <a href="pygrib.index-class.html#__call__" 
  class="link">__call__</a> method can then be used to selected grib 
  messages based on specified values of indexed keys. Unlike <a 
  href="pygrib.open-class.html#select" class="link">open.select</a>, 
  containers or callables cannot be used to select multiple key values. 
  However, using <a href="pygrib.index-class.html#select" 
  class="link">index.select</a> is much faster than <a 
  href="pygrib.open-class.html#select" class="link">open.select</a>.</p>
  <p><b>Warning</b>:  Searching for data within multi-field grib messages 
  does not work using an index (and is not supported by the <a 
  href="https://software.ecmwf.int/wiki/display/GRIB/Home" 
  target="_top">GRIB API</a> library).  NCEP often puts u and v winds 
  together in a single multi-field grib message.  You will get incorrect 
  results if you try to use an index to find data in these messages.  Use 
  the slower, but more robust <a href="pygrib.open-class.html#select" 
  class="link">open.select</a> in this case.</p>
  <p>If no key are given (i.e. *args is empty), it is assumed the filename 
  represents a previously saved index (created using the 
  <code>grib_index_build</code> tool or <a 
  href="pygrib.index-class.html#write" class="link">index.write</a>) 
  instead of a GRIB file.</p>
  <p>Example usage:</p>
<pre class="py-doctest">
<span class="py-prompt">&gt;&gt;&gt; </span><span class="py-keyword">import</span> pygrib
<span class="py-prompt">&gt;&gt;&gt; </span>grbindx=pygrib.index(<span class="py-string">'sampledata/gfs.grb'</span>,<span class="py-string">'shortName'</span>,<span class="py-string">'typeOfLevel'</span>,<span class="py-string">'level'</span>)
<span class="py-prompt">&gt;&gt;&gt; </span>grbindx.keys
<span class="py-output">['shortName', 'level']</span>
<span class="py-output"></span><span class="py-prompt">&gt;&gt;&gt; </span>selected_grbs=grbindx.select(shortName=<span class="py-string">'gh'</span>,typeOfLevel=<span class="py-string">'isobaricInhPa'</span>,level=500)
<span class="py-prompt">&gt;&gt;&gt; </span><span class="py-keyword">for</span> grb <span class="py-keyword">in</span> selected_grbs:
<span class="py-prompt">&gt;&gt;&gt; </span>    grb
<span class="py-output">1:Geopotential height:gpm (instant):regular_ll:isobaricInhPa:level 500 Pa:fcst time 72 hrs:from 200412091200:lo res cntl fcst</span>
<span class="py-output"></span><span class="py-prompt">&gt;&gt;&gt; </span><span class="py-comment"># __call__ method does same thing as select</span>
<span class="py-prompt">&gt;&gt;&gt; </span>selected_grbs=grbindx(shortName=<span class="py-string">'u'</span>,typeOfLevel=<span class="py-string">'isobaricInhPa'</span>,level=250)
<span class="py-prompt">&gt;&gt;&gt; </span><span class="py-keyword">for</span> grb <span class="py-keyword">in</span> selected_grbs:
<span class="py-prompt">&gt;&gt;&gt; </span>    grb
<span class="py-output">1:u-component of wind:m s**-1 (instant):regular_ll:isobaricInhPa:level 250 Pa:fcst time 72 hrs:from 200412091200:lo res cntl fcst</span>
<span class="py-output"></span><span class="py-prompt">&gt;&gt;&gt; </span>grbindx.write(<span class="py-string">'gfs.grb.idx'</span>) <span class="py-comment"># save index to a file</span>
<span class="py-prompt">&gt;&gt;&gt; </span>grbindx.close()
<span class="py-prompt">&gt;&gt;&gt; </span>grbindx = pygrib.index(<span class="py-string">'gfs.grb.idx'</span>) <span class="py-comment"># re-open index (no keys specified)</span>
<span class="py-prompt">&gt;&gt;&gt; </span>grbindx.keys <span class="py-comment"># not set when opening a saved index file.</span>
<span class="py-output">None</span>
<span class="py-output"></span><span class="py-prompt">&gt;&gt;&gt; </span><span class="py-keyword">for</span> grb <span class="py-keyword">in</span> selected_grbs:
<span class="py-prompt">&gt;&gt;&gt; </span>    grb
<span class="py-output">1:u-component of wind:m s**-1 (instant):regular_ll:isobaricInhPa:level 250 Pa:fcst time 72 hrs:from 200412091200:lo res cntl fcst</span></pre>

<!-- ==================== INSTANCE METHODS ==================== -->
<a name="section-InstanceMethods"></a>
<table class="summary" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr bgcolor="#70b0f0" class="table-header">
  <td align="left" colspan="2" class="table-header">
    <span class="table-header">Instance Methods</span></td>
</tr>
<tr>
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">&nbsp;</span>
    </td><td class="summary">
      <table width="100%" cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td><span class="summary-sig"><a name="__call__"></a><span class="summary-sig-name">__call__</span>(<span class="summary-sig-arg">...</span>)</span><br />
      same as <a href="pygrib.index-class.html#select" 
      class="link">select</a></td>
          <td align="right" valign="top">
            
            
          </td>
        </tr>
      </table>
      
    </td>
  </tr>
<tr>
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">&nbsp;</span>
    </td><td class="summary">
      <table width="100%" cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td><span class="summary-sig"><a href="pygrib.index-class.html#__init__" class="summary-sig-name">__init__</a>(<span class="summary-sig-arg">filename</span>,
        <span class="summary-sig-arg">*args</span>)</span><br />
      x.__init__(...) initializes x; see help(type(x)) for signature</td>
          <td align="right" valign="top">
            
            
          </td>
        </tr>
      </table>
      
    </td>
  </tr>
<tr>
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">a new object with type S, a subtype of T</span>
    </td><td class="summary">
      <table width="100%" cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td><span class="summary-sig"><a href="pygrib.index-class.html#__new__" class="summary-sig-name">__new__</a>(<span class="summary-sig-arg">T</span>,
        <span class="summary-sig-arg">S</span>,
        <span class="summary-sig-arg">...</span>)</span></td>
          <td align="right" valign="top">
            
            
          </td>
        </tr>
      </table>
      
    </td>
  </tr>
<tr>
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">&nbsp;</span>
    </td><td class="summary">
      <table width="100%" cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td><span class="summary-sig"><a name="close"></a><span class="summary-sig-name">close</span>()</span><br />
      deallocate C structures associated with class instance</td>
          <td align="right" valign="top">
            
            
          </td>
        </tr>
      </table>
      
    </td>
  </tr>
<tr>
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">&nbsp;</span>
    </td><td class="summary">
      <table width="100%" cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td><span class="summary-sig"><a href="pygrib.index-class.html#select" class="summary-sig-name">select</a>(<span class="summary-sig-arg">**kwargs</span>)</span><br />
      return a list of <a href="pygrib.gribmessage-class.html" 
      class="link">gribmessage</a> instances from grib index object 
      corresponding to specific values of indexed keys (given by kwargs).</td>
          <td align="right" valign="top">
            
            
          </td>
        </tr>
      </table>
      
    </td>
  </tr>
<tr>
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">&nbsp;</span>
    </td><td class="summary">
      <table width="100%" cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td><span class="summary-sig"><a name="write"></a><span class="summary-sig-name">write</span>(<span class="summary-sig-arg">filename</span>)</span><br />
      save grib index to file</td>
          <td align="right" valign="top">
            
            
          </td>
        </tr>
      </table>
      
    </td>
  </tr>
  <tr>
    <td colspan="2" class="summary">
    <p class="indent-wrapped-lines"><b>Inherited from <code>object</code></b>:
      <code>__delattr__</code>,
      <code>__format__</code>,
      <code>__getattribute__</code>,
      <code>__hash__</code>,
      <code>__reduce__</code>,
      <code>__reduce_ex__</code>,
      <code>__repr__</code>,
      <code>__setattr__</code>,
      <code>__sizeof__</code>,
      <code>__str__</code>,
      <code>__subclasshook__</code>
      </p>
    </td>
  </tr>
</table>
<!-- ==================== INSTANCE VARIABLES ==================== -->
<a name="section-InstanceVariables"></a>
<table class="summary" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr bgcolor="#70b0f0" class="table-header">
  <td align="left" colspan="2" class="table-header">
    <span class="table-header">Instance Variables</span></td>
</tr>
<tr>
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">&nbsp;</span>
    </td><td class="summary">
        <a href="pygrib.index-class.html#keys" class="summary-name">keys</a><br />
      list of strings containing keys used in the index.
    </td>
  </tr>
<tr>
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">&nbsp;</span>
    </td><td class="summary">
        <a href="pygrib.index-class.html#types" class="summary-name">types</a><br />
      if keys are typed, this list contains the type declarations 
      (<code>l</code>, <code>s</code> or <code>d</code>).
    </td>
  </tr>
</table>
<!-- ==================== PROPERTIES ==================== -->
<a name="section-Properties"></a>
<table class="summary" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr bgcolor="#70b0f0" class="table-header">
  <td align="left" colspan="2" class="table-header">
    <span class="table-header">Properties</span></td>
</tr>
<tr>
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">&nbsp;</span>
    </td><td class="summary">
        <a name="name"></a><span class="summary-name">name</span>
    </td>
  </tr>
  <tr>
    <td colspan="2" class="summary">
    <p class="indent-wrapped-lines"><b>Inherited from <code>object</code></b>:
      <code>__class__</code>
      </p>
    </td>
  </tr>
</table>
<!-- ==================== METHOD DETAILS ==================== -->
<a name="section-MethodDetails"></a>
<table class="details" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr bgcolor="#70b0f0" class="table-header">
  <td align="left" colspan="2" class="table-header">
    <span class="table-header">Method Details</span></td>
</tr>
</table>
<a name="__init__"></a>
<div>
<table class="details" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr><td>
  <table width="100%" cellpadding="0" cellspacing="0" border="0">
  <tr valign="top"><td>
  <h3 class="epydoc"><span class="sig"><span class="sig-name">__init__</span>(<span class="sig-arg">filename</span>,
        <span class="sig-arg">*args</span>)</span>
    <br /><em class="fname">(Constructor)</em>
  </h3>
  </td><td align="right" valign="top"
    >&nbsp;
    </td>
  </tr></table>
  
  <p>x.__init__(...) initializes x; see help(type(x)) for signature</p>
  <dl class="fields">
    <dt>Overrides:
        object.__init__
    </dt>
  </dl>
</td></tr></table>
</div>
<a name="__new__"></a>
<div>
<table class="details" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr><td>
  <table width="100%" cellpadding="0" cellspacing="0" border="0">
  <tr valign="top"><td>
  <h3 class="epydoc"><span class="sig"><span class="sig-name">__new__</span>(<span class="sig-arg">T</span>,
        <span class="sig-arg">S</span>,
        <span class="sig-arg">...</span>)</span>
  </h3>
  </td><td align="right" valign="top"
    >&nbsp;
    </td>
  </tr></table>
  
  
  <dl class="fields">
    <dt>Returns: a new object with type S, a subtype of T</dt>
    <dt>Overrides:
        object.__new__
    </dt>
  </dl>
</td></tr></table>
</div>
<a name="select"></a>
<div>
<table class="details" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr><td>
  <table width="100%" cellpadding="0" cellspacing="0" border="0">
  <tr valign="top"><td>
  <h3 class="epydoc"><span class="sig"><span class="sig-name">select</span>(<span class="sig-arg">**kwargs</span>)</span>
  </h3>
  </td><td align="right" valign="top"
    >&nbsp;
    </td>
  </tr></table>
  
  <p>return a list of <a href="pygrib.gribmessage-class.html" 
  class="link">gribmessage</a> instances from grib index object 
  corresponding to specific values of indexed keys (given by kwargs). 
  Unlike <a href="pygrib.open-class.html#select" 
  class="link">open.select</a>, containers or callables cannot be used to 
  select multiple key values. However, using <a 
  href="pygrib.index-class.html#select" class="link">index.select</a> is 
  much faster than <a href="pygrib.open-class.html#select" 
  class="link">open.select</a>.</p>
  <p>Example usage:</p>
<pre class="py-doctest">
<span class="py-prompt">&gt;&gt;&gt; </span><span class="py-keyword">import</span> pygrib
<span class="py-prompt">&gt;&gt;&gt; </span>grbindx=pygrib.index(<span class="py-string">'sampledata/gfs.grb'</span>,<span class="py-string">'shortName'</span>,<span class="py-string">'typeOfLevel'</span>,<span class="py-string">'level'</span>)
<span class="py-prompt">&gt;&gt;&gt; </span>selected_grbs=grbindx.select(shortName=<span class="py-string">'gh'</span>,typeOfLevel=<span class="py-string">'isobaricInhPa'</span>,level=500)
<span class="py-prompt">&gt;&gt;&gt; </span><span class="py-keyword">for</span> grb <span class="py-keyword">in</span> selected_grbs:
<span class="py-prompt">&gt;&gt;&gt; </span>    grb
<span class="py-output">1:Geopotential height:gpm (instant):regular_ll:isobaricInhPa:level 500 Pa:fcst time 72 hrs:from 200412091200:lo res cntl fcst</span>
<span class="py-output"></span><span class="py-prompt">&gt;&gt;&gt; </span><span class="py-comment"># __call__ method does same thing as select</span>
<span class="py-prompt">&gt;&gt;&gt; </span>selected_grbs=grbindx(shortName=<span class="py-string">'u'</span>,typeOfLevel=<span class="py-string">'isobaricInhPa'</span>,level=250)
<span class="py-prompt">&gt;&gt;&gt; </span><span class="py-keyword">for</span> grb <span class="py-keyword">in</span> selected_grbs:
<span class="py-prompt">&gt;&gt;&gt; </span>    grb
<span class="py-output">1:u-component of wind:m s**-1 (instant):regular_ll:isobaricInhPa:level 250 Pa:fcst time 72 hrs:from 200412091200:lo res cntl fcst</span>
<span class="py-output"></span><span class="py-prompt">&gt;&gt;&gt; </span>grbindx.close()</pre>
  <dl class="fields">
  </dl>
</td></tr></table>
</div>
<br />
<!-- ==================== INSTANCE VARIABLE DETAILS ==================== -->
<a name="section-InstanceVariableDetails"></a>
<table class="details" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr bgcolor="#70b0f0" class="table-header">
  <td align="left" colspan="2" class="table-header">
    <span class="table-header">Instance Variable Details</span></td>
</tr>
</table>
<a name="keys"></a>
<div>
<table class="details" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr><td>
  <h3 class="epydoc">keys</h3>
  list of strings containing keys used in the index.  Set to 
  <code>None</code> when opening a previously saved grib index file.
  <dl class="fields">
  </dl>
</td></tr></table>
</div>
<a name="types"></a>
<div>
<table class="details" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr><td>
  <h3 class="epydoc">types</h3>
  if keys are typed, this list contains the type declarations 
  (<code>l</code>, <code>s</code> or <code>d</code>). Type declarations are
  specified by appending to the key name (i.e. <code>level:l</code> will 
  search for values of <code>level</code> that are longs). Set to 
  <code>None</code> when opening a previously saved grib index file.
  <dl class="fields">
  </dl>
</td></tr></table>
</div>
<br />
<!-- ==================== NAVIGATION BAR ==================== -->
<table class="navbar" border="0" width="100%" cellpadding="0"
       bgcolor="#a0c0ff" cellspacing="0">
  <tr valign="middle">
  <!-- Home link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="pygrib-module.html">Home</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Tree link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="module-tree.html">Trees</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Index link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="identifier-index.html">Indices</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Help link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="help.html">Help</a>&nbsp;&nbsp;&nbsp;</th>

      <th class="navbar" width="100%"></th>
  </tr>
</table>
<table border="0" cellpadding="0" cellspacing="0" width="100%%">
  <tr>
    <td align="left" class="footer">
    Generated by Epydoc 3.0.1 on Mon Dec 29 14:23:16 2014
    </td>
    <td align="right" class="footer">
      <a target="mainFrame" href="http://epydoc.sourceforge.net"
        >http://epydoc.sourceforge.net</a>
    </td>
  </tr>
</table>

<script type="text/javascript">
  <!--
  // Private objects are initially displayed (because if
  // javascript is turned off then we want them to be
  // visible); but by default, we want to hide them.  So hide
  // them unless we have a cookie that says to show them.
  checkCookie();
  // -->
</script>
</body>
</html>
